#include <rabbit/console.h>
#include <rabbit/entry.h>
#include <asm/cmos.h>
#include <asm/system.h>
#include <init/dt.h>
#include <boot/multiboot.h>
#include <init/timer.h>
#include <global.h>
#include <mm.h>

extern volatile u32int tick;
extern void init_8259(void);

int main(struct multiboot *mboot_ptr)
{
	HIGH_MEMORY = mboot_ptr->mem_upper*1024 + 1024*1024;
	HIGH_MEMORY &= 0xffffF000; // keep 1 page align
	//LOW_MEMORY = 4 * 1024 * 1024; // reserve 4MB mem for kernel, quite big, huh
	// end here

	console_clear();
	printk("Initializing descriptor tables...\n");
	init_dt();
	printk("Initializing trap gates...\n");
	init_trap();
	printk("Initializing paging...\n");
	init_paging();
	printk("Initializing timer...\n");
	init_timer(50);				//Frequency 50Hz
	printk("Booting kernel...\n");

	//init_kernel();


	init_mm();
	mem_info();
	printk("\n");

	/*
	u32int *ptr = (u32int *)0xa000000;
	u32int t = *ptr;
	*/
	u32int *p0 = (u32int *)0x00400000;
	u32int *p1 = (u32int *)0x00000004;
	u32int *p2 = (u32int *)0x00000008;
	u32int *p3 = (u32int *)0x0000000c;
	printk("%08x %08x %08x %08x\n", *p0, *p1, *p2, *p3);

	u32int *ptr = (u32int *)0xA000FFFF;
	*ptr = 101;
	u32int t = *ptr;
	printk("t = %d\n", t);

	return 0;
}

